package com.igroupes.ovineherd.model.Style;

import com.igroupes.ovineherd.exception.ModelException;
import com.igroupes.ovineherd.model.enums.FormKey;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.util.List;

/**
 * 复选框样式
 */
@EqualsAndHashCode(callSuper = true)
@Data
@ToString(callSuper = true)
public class CheckboxStyle extends BasicStyle{
    private List<Group> options;
    private Boolean inline = false; //是否显示为一行
    private Integer columnsCount = 3; //选项按几列显示，默认为一列
    private Boolean joinValues = true; //拼接值
    private Boolean extractValue = false;
    private Integer maxLength = 99999999 ;
    private Boolean checkAll = true;
    public CheckboxStyle(String label, Object value, List<Group> options) {
        super(label, value);
        this.type = FormKey.CHECKBOX.getCode();
        this.options = options;
    }
    public CheckboxStyle(String label, Object value, List<Group> options, Boolean joinValues, Boolean extractValue, Integer maxLength) {
        this(label, value, options);
        this.joinValues = joinValues;
        this.extractValue = extractValue;
        this.maxLength = maxLength;
    }
    public CheckboxStyle() {

    }

    @Override
    public Boolean verify(Object o) {
        if(!(o instanceof CheckboxStyle)){
            throw new ModelException("校验style类类型错误， check");
        }
        CheckboxStyle style = (CheckboxStyle) o;
        super.verify(o);
//        if(!style.getDisabled()){
//            for (Object g :
//                    style.getOptions()) {
//                if(!(g instanceof Group)){
//                    throw new ModelException(style.getLabel()+"传值类型错误");
//                }
//                Group group1 = (Group) g;
//                group1.verify(group1);
//            }
//        }
        return true;
    }
}
